package com.example.mytodo

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi


class DBHelper(
    context: Context?,
    name:String?,
    version:Int
):SQLiteOpenHelper(context,name,null,version)
 {
    val TAG = "@@DBHelper"

    override fun onCreate(db: SQLiteDatabase) {
        Log.d(TAG,"DB onCreating")
        db.execSQL("CREATE TABLE IF NOT EXISTS ${Atodo.TABLE} (\n" +
                "\t${Atodo.T_ID} integer PRIMARY KEY autoincrement,\n" +
                "\t${Atodo.T_TODOSTRING} text,\n" +
                "\t${Atodo.T_TIME} REAL,\n" +
                "\t${Atodo.T_STATE} INT)")
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldversion: Int, newversion: Int) {
        Log.d(TAG,"DB on upgrade ,version from $oldversion to $newversion")


    }

     fun DeleteTodo(db:SQLiteDatabase, id:Int)
     {
         Log.d(TAG,"toEdit")
         db.execSQL("DELETE FROM ${Atodo.TABLE} WHERE ${Atodo.T_ID} = $id")

     }


     fun EditTodo(db:SQLiteDatabase, id:Int,todostring:String)
     {
         Log.d(TAG,"toEdit")

         db.execSQL("UPDATE ${Atodo.TABLE} SET ${Atodo.T_TODOSTRING} = \"$todostring\" WHERE ${Atodo.T_ID} = $id")

         // Log.d(TAG,"UPDATE ${Atodo.TABLE} SET ${Atodo.T_TODOSTRING} = \"$todostring\" WHERE ${Atodo.T_ID} = $id")
     }



}